package com.xyhy.core.base.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Persistable;

import com.xyhy.core.base.service.ICrudService;

public abstract class BaseController<PO extends Persistable<ID>, ID, SERVICE extends ICrudService<PO, ID>> implements ICrudController<PO, PO, PO, ID> {
  protected @Autowired SERVICE service;

  @Override
  public PO findById(ID id) {
    return service.findById(id);
  }

  @Override
  public PO add(PO data) throws Exception {
    return this.save(data);
  }

  @Override
  public PO update(PO data) throws Exception {
    return this.save(data);
  }

  @Override
  public ID delete(ID id) {
    service.delete(id);
    return id;
  }

  @Override
  public List<ID> batchDelete(List<ID> ids) {
    service.deleteInBatch(ids);
    return ids;
  }

  public PO save(PO data) {
    return service.save(data);
  }
}
